package com.tangkun.environment.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.tangkun.environment.R;
import com.tangkun.environment.entity.base.CommonReturn;
import com.tangkun.environment.network.MySubscribe;
import com.tangkun.environment.rx.RxActivityHelper;
import com.tangkun.environment.utils.JumpHelper;
import com.tangkun.environment.utils.Utils;

import org.simple.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 意见反馈
 */
public class YiJianFanKuiActivity extends BaseActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.next)
    TextView next;
    @BindView(R.id.et_yijianfankui_neirong)
    EditText etYijianfankuiNeirong;
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yijianfankui);
        mContext = this;
        ButterKnife.bind(this);
        title.setText("意见反馈");
        next.setText("提交");
    }

    @OnClick({R.id.back, R.id.next})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                Utils.hideSoftKeyboard(YiJianFanKuiActivity.this, back);
                JumpHelper.finish(mContext);
                break;
            case R.id.next://提交
                String description = etYijianfankuiNeirong.getText().toString().trim();
                if (!TextUtils.isEmpty(description)) {
                    feedbackSave(description);
                } else {
                    showToast("请输入反馈内容");
                }
                break;
        }
    }

    private void feedbackSave(String description) {
        Map<String, String> map = new HashMap<>();
        map.put("description", description);//反馈内容
        fromNetwork.feedbackSave(map)
                .compose(new RxActivityHelper<CommonReturn>().ioMain(YiJianFanKuiActivity.this, true))
                .subscribe(new MySubscribe<CommonReturn>(mContext, true) {
                    @Override
                    protected void success(CommonReturn resultBean) {
                        showToast("提交成功");
                        Utils.hideSoftKeyboard(YiJianFanKuiActivity.this, back);
                        JumpHelper.finish(mContext);
                    }

                    @Override
                    protected void onMyError(String errorMessage) {
                        showToast(errorMessage);
                    }
                });
    }


}
